package com.tian.view.draw

import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import com.tian.view.BaseRecyclerAdapter
import com.tian.view.common.BaseListFragment
import com.tian.view.draw.advance.DrawAdvanceFragment
import com.tian.view.draw.common.CommonDrawFragment
import com.tian.view.draw.fermode.DrawXFermodeFragment
import com.tian.view.draw.paint.DrawPaintFragment
import com.tian.view.draw.path.PathFragment
import com.tian.view.draw.region.RegionFragment
import com.tian.view.draw.shader.DrawShaderFragment
import com.tian.view.draw.text.DrawTextFragment
import com.tian.view.helper.FragmentHelper

/**
 * @author tiansongtao, Email:tiansongtao@up366.com
 * @date 2022/12/29 17:26
 */
class DrawListFragment : BaseListFragment() {
    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        (requireActivity() as AppCompatActivity).supportActionBar?.title = "View Draw"
    }

    override fun getRecyclerViewAdapter(): BaseRecyclerAdapter {
        val adapter = BaseRecyclerAdapter()
        adapter.itemClickListener = object : BaseRecyclerAdapter.OnItemClickListener {
            override fun onItemClick(dataHolder: BaseRecyclerAdapter.DataHolder, position: Int) {
                val fragment = dataHolder.o1 as Fragment
                FragmentHelper.showFragment(requireActivity(), android.R.id.content, fragment, true,
                        dataHolder.o as String)
            }
        }
        return adapter
    }

    override fun onHiddenChanged(hidden: Boolean) {
        super.onHiddenChanged(hidden)
        if (!hidden) {
            (requireActivity() as AppCompatActivity).supportActionBar?.title = "View Draw"
        }
    }


    override fun getAdapterData(): MutableList<BaseRecyclerAdapter.DataHolder> {
        val datas = mutableListOf<BaseRecyclerAdapter.DataHolder>()
        datas.add(BaseRecyclerAdapter.DataHolder(BaseRecyclerAdapter.TYPE_COMMON_BUTTON, "普通图形绘制",
                CommonDrawFragment()))
        datas.add(BaseRecyclerAdapter.DataHolder(BaseRecyclerAdapter.TYPE_COMMON_BUTTON, "draw path复合路径",
                PathFragment()))
        datas.add(BaseRecyclerAdapter.DataHolder(BaseRecyclerAdapter.TYPE_COMMON_BUTTON, "Region区域",
                RegionFragment()))
        datas.add(BaseRecyclerAdapter.DataHolder(BaseRecyclerAdapter.TYPE_COMMON_BUTTON, "drawText绘制文字",
                DrawTextFragment()))
        datas.add(BaseRecyclerAdapter.DataHolder(BaseRecyclerAdapter.TYPE_COMMON_BUTTON, "Paint画笔特殊用法",
                DrawPaintFragment()))
        datas.add(BaseRecyclerAdapter.DataHolder(BaseRecyclerAdapter.TYPE_COMMON_BUTTON, "绘图进阶",
                DrawAdvanceFragment()))
        datas.add(BaseRecyclerAdapter.DataHolder(BaseRecyclerAdapter.TYPE_COMMON_BUTTON, "Shader",
                DrawShaderFragment()))
        datas.add(BaseRecyclerAdapter.DataHolder(BaseRecyclerAdapter.TYPE_COMMON_BUTTON, "Paint混合模式",
                DrawXFermodeFragment()))
        return datas
    }
}